import request from "@/utils/request";

let baseUrl = window.scjConfig.baseUrl
let baseUrl2 = import.meta.env.MODE == "development" ? '/base-api' : window.scjConfig.jlyBaseUrl //
//let baseUrl = window.scjConfig.baseUrl
//let baseUrl2 = "http://10.11.21.20:8920"
//let baseUrl2 = "http://192.168.31.79:8920"
const resDataFn = (promise) => {
  return new Promise((resolve, reject) => {
    promise
      .then((d) => {
        if (d.code === "0" && d.data !== undefined) {
          resolve(d.data);
        } else if (typeof d == "object") {
          resolve(d);
        } else {
          reject(d.message);
        }
      })
      .catch((err) => {
        reject(err);
      });
  });
};
/** 处理查询的通用方法,只传需要筛选的参数 */
function getFilter(data = { pageNum: 1, pageSize: 10 }) {
  var filter = {
    pageNum: data.pageNum,
    pageSize: data.pageSize,
    groups: [],
    rules: [],
    //orderBys: [{ fieldName: "createOn", order: "DESC" }],//默认根据createOn创建时间倒序排列
    orderBys: [],//默认根据createOn创建时间倒序排列

  }
  // if (data.simpleSearchText) {
  //     filter.groups.push({
  //         groupOp: 'OR',
  //         rules: [
  //             {
  //                 field: 'title',
  //                 data: data.simpleSearchText,
  //                 opType: 'Contains',
  //             },
  //             {
  //                 field: 'content',
  //                 data: data.simpleSearchText,
  //                 opType: 'Contains',
  //             },
  //         ],
  //     })
  // }
  let { pageNum, pageSize, ...d } = data
  for (const key in d) {
    if (Object.prototype.hasOwnProperty.call(d, key)) {
      if (d[key] !== "") {
        filter.rules.push({
          field: key,
          data: d[key],
          opType: 'Equals',
        })
      }
    }
  }
  // if (data.name) {
  //   filter.rules.push({
  //     field: 'businessName',
  //     data: data.name,
  //     opType: 'Contains',
  //   })
  // }
  // if (dateRange.value && dateRange.value.length > 0) {
  //   filter.rules.push({
  //     field: 'createOn',
  //     data: dateRange.value[0] + ' 00:00:00',
  //     opType: 'GreaterThan',
  //   })
  //   filter.rules.push({
  //     field: 'createOn',
  //     data: dateRange.value[1] + ' 23:59:59',
  //     opType: 'LessThan',
  //   })
  // }
  return filter
}
/** 示例 */
export function getNlpsearchFilter(data) {
  return resDataFn(request({
    url: `${baseUrl}/nlpsearch/query/case/filter`,
    method: "post",
    data
  }));
}
//指标数据源---列表
export function indicatorDb(data) {
  return request({
    url: `${baseUrl}/api/indicator_db/`,
    method: "post",
    data: getFilter(data)
  })
}
//指标数据源---新增
export function indicatorDbCreate(data) {
  return request({
    url: `${baseUrl}/api/indicator_db/create`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标数据源---删除
export function indicatorDbDelete(data) {
  return request({
    url: `${baseUrl}/api/indicator_db/delete`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标数据源---明细
export function indicatorDbDetail(data) {
  return request({
    url: `${baseUrl}/api/indicator_db/detail`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标数据源---更新
export function indicatorDbSave(data) {
  return request({
    url: `${baseUrl}/api/indicator_db/save`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标集---列表
export function indicatorSet(data) {
  return request({
    url: `${baseUrl}/api/indicator_set/`,
    method: "post",
    data: getFilter(data)
  })
}
//指标集---新增
export function indicatorCreate(data) {
  return request({
    url: `${baseUrl}/api/indicator_set/create`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标集---修改
export function indicatorSave(data) {
  return request({
    url: `${baseUrl}/api/indicator_set/save`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标集---详情
export function indicatorDetail(data) {
  return request({
    url: `${baseUrl}/api/indicator_set/detail`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标集---删除
export function indicatorDelete(data) {
  return request({
    url: `${baseUrl}/api/indicator_set/delete`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//通用查询方法
export function indicatorQueryMap(data) {
  return request({
    url: `${baseUrl}/api/indicator/query/map`,
    method: "post",
    data,
  })
}




//指标---列表
export function indicatorZhibiao(data) {
  return request({
    url: `${baseUrl}/api/indicator/`,
    method: "post",
    data: getFilter(data)
  })
}
//指标---新增
export function indicatorZhibiaoCreate(data) {
  return request({
    url: `${baseUrl}/api/indicator/create`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标---修改
export function indicatorZhibiaoSave(data) {
  return request({
    url: `${baseUrl}/api/indicator/save`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标---详情
export function indicatorZhibiaoDetail(data) {
  return request({
    url: `${baseUrl}/api/indicator/detail`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//指标---删除
export function indicatorZhibiaoDelete(data) {
  return request({
    url: `${baseUrl}/api/indicator/delete`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//中心简介---列表
export function cmsCentreBlurb(data) {
  return request({
    url: `${baseUrl2}/api/cmsCentreBlurb/`,
    method: "post",
    data: getFilter(data)
  })
}
//中心简介---新增
export function cmsCentreBlurbCreate(data) {
  return request({
    url: `${baseUrl2}/api/cmsCentreBlurb/create`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//中心简介---详情
export function cmsCentreBlurbDetail(data) {
  return request({
    url: `${baseUrl2}/api/cmsCentreBlurb/detail`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//中心简介---修改
export function cmsCentreBlurbSave(data) {
  return request({
    url: `${baseUrl2}/api/cmsCentreBlurb/save`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//中心简介修改---列表
export function cmsCentreBlurbDetails(data) {
  return request({
    url: `${baseUrl2}/api/cmsCentreBlurbDetails/`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//中心简介修改---新增
export function cmsCentreBlurbDetailsCreate(data) {
  return request({
    url: `${baseUrl2}/api/cmsCentreBlurbDetails/create`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//中心简介修改---详情
export function cmsCentreBlurbDetailsDetail(data) {
  return request({
    url: `${baseUrl2}/api/cmsCentreBlurbDetails/detail`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//中心简介修改---修改
export function cmsCentreBlurbDetailsSave(data) {
  return request({
    url: `${baseUrl2}/api/cmsCentreBlurbDetails/save`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//科技成果---列表
export function cmsAchievement(data) {
  return request({
    url: `${baseUrl2}/api/cmsAchievement/`,
    method: "post",
    data: getFilter(data)
  })
}
//科技成果---新增
export function cmsAchievementCreate(data) {
  return request({
    url: `${baseUrl2}/api/cmsAchievement/create`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//科技成果---详情
export function cmsAchievementDetail(data) {
  return request({
    url: `${baseUrl2}/api/cmsAchievement/detail`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//科技成果---修改
export function cmsAchievementSave(data) {
  return request({
    url: `${baseUrl2}/api/cmsAchievement/save`,
    method: "post",
    data: { data, "rid": "0" }
  })
}

//会议培训---列表
export function cmsTraining(data) {
  return request({
    url: `${baseUrl2}/api/cmsTraining/`,
    method: "post",
    data: getFilter(data)
  })
}
//会议培训---新增
export function cmsTrainingCreate(data) {
  return request({
    url: `${baseUrl2}/api/cmsTraining/create`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//会议培训---详情
export function cmsTrainingDetail(data) {
  return request({
    url: `${baseUrl2}/api/cmsTraining/detail`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//会议培训---修改
export function cmsTrainingSave(data) {
  return request({
    url: `${baseUrl2}/api/cmsTraining/save`,
    method: "post",
    data: { data, "rid": "0" }
  })
}

//典型案例---列表
export function cmsClassicCase(data) {
  return request({
    url: `${baseUrl2}/api/cmsClassicCase/`,
    method: "post",
    data: getFilter(data)
  })
}
//典型案例---新增
export function cmsClassicCaseCreate(data) {
  return request({
    url: `${baseUrl2}/api/cmsClassicCase/create`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//典型案例---详情
export function cmsClassicCaseDetail(data) {
  return request({
    url: `${baseUrl2}/api/cmsClassicCase/detail`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//典型案例---修改
export function cmsClassicCaseSave(data) {
  return request({
    url: `${baseUrl2}/api/cmsClassicCase/save`,
    method: "post",
    data: { data, "rid": "0" }
  })
}

//文章---列表
export function cmsArticle(data) {
  return request({
    url: `${baseUrl2}/api/cmsArticle/`,
    method: "post",
    data: getFilter(data)
  })
}
//文章---新增
export function cmsArticleCreate(data) {
  return request({
    url: `${baseUrl2}/api/cmsArticle/create`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//文章---详情
export function cmsArticleDetail(data) {
  return request({
    url: `${baseUrl2}/api/cmsArticle/detail`,
    method: "post",
    data: { data, "rid": "0" }
  })
}
//文章---修改
export function cmsArticleSave(data) {
  return request({
    url: `${baseUrl2}/api/cmsArticle/save`,
    method: "post",
    data: { data, "rid": "0" }
  })
}